<template>
<div>
    <el-row class="myCreateOrderrow6" type="flex" justify="center">
        <el-col :span="13" class="myCreateOrdercol6">
            <div class="myCreateOrdercol6SpanLeftdiv">
                <span class="myCreateOrdercol6SpanLeft">hggood 发货订单</span>
            </div>
        </el-col>
        <el-col :span="4" class="myCreateOrdercol6">
            <div class="myCreateOrdercol6SpanRightdiv">
                <span class="myCreateOrdercol6SpanRight">类型</span>
            </div>
        </el-col>
        <el-col :span="4" class="myCreateOrdercol6">
            <div class="myCreateOrdercol6SpanRightdiv" style="text-align: left;">
                <span class="myCreateOrdercol6SpanRight" style="margin-left:10px">单价</span>
            </div>
        </el-col>
        <el-col :span="3" class="myCreateOrdercol6">
            <div class="myCreateOrdercol6SpanRightdiv">
                <span class="myCreateOrdercol6SpanRight">数量</span>
            </div>
        </el-col>
    </el-row>
    <el-row class="myCreateOrderrow7" type="flex" justify="center"
    v-for="(CCSList , index) in CCList" :key="index">
        <el-col :span="14" class="myCreateOrdercol7">
            <div class="myCreateOrdercol7Leftdiv">
                <el-popover placement="right-start" trigger="hover" width="160">
                    <img class="BigPng" :src="BigPNGinfo[index]">
                    <img class="SmallJPG" slot="reference" :src="SmallJPGinfo[index]">
                </el-popover>
                <span class="ProductText" :title="CCSList.title">
                    {{CCSList.title}}</span>
            </div>
        </el-col>
        <el-col :span="4" class="myCreateOrdercol7">
            <div class="myCreateOrdercol7SpanRightdiv">
                <span class="myCreateOrdercol7SpanRight">
                    {{CCSList.title.slice(2)}} 
                </span>
            </div>
        </el-col>
        <el-col :span="4" class="myCreateOrdercol7">
            <div class="myCreateOrdercol7SpanRightdiv">
                <span class="myCreateOrdercol7SpanRight">
                    ￥{{CCSList.price}}
                </span>
            </div>
        </el-col>
        <el-col :span="2" class="myCreateOrdercol7">
            <div class="myCreateOrdercol7SpanRightdiv" style="text-align: center;">
                <span class="myCreateOrdercol7SpanRight" style="margin-left:14px">
                    {{CCSList.num}}
                </span>
            </div>
        </el-col>
    </el-row>
    <!-- 测试专用row -->
    <!-- <el-row class="myCreateOrderrow7" type="flex" justify="center">
        <el-col :span="14" class="myCreateOrdercol7">
            <div class="myCreateOrdercol7Leftdiv">
                <img class="SmallJPG" slot="reference" src="../../../assets/portal/11DELLran7000gold/1.jpg">
                <span class="ProductText" title="星14青春版十一代酷睿i5集显14寸轻薄办公高性能笔记本电脑">
                    星14青春版十一代酷睿i5集显14寸轻薄办公高性能笔记本电脑</span>
            </div>
        </el-col>
        <el-col :span="4" class="myCreateOrdercol7">
            <div class="myCreateOrdercol7SpanRightdiv">
                <span class="myCreateOrdercol7SpanRight">
                    R3-5300U 8G 256G 
                </span>
            </div>
        </el-col>
        <el-col :span="4" class="myCreateOrdercol7">
            <div class="myCreateOrdercol7SpanRightdiv">
                <span class="myCreateOrdercol7SpanRight">
                    ￥4099
                </span>
            </div>
        </el-col>
        <el-col :span="2" class="myCreateOrdercol7">
            <div class="myCreateOrdercol7SpanRightdiv" style="text-align: center;">
                <span class="myCreateOrdercol7SpanRight" style="margin-left:0px;margin-top:14px">
                    1
                </span>
            </div>
        </el-col>
    </el-row> -->
    <el-row class="myCreateOrderrow8" type="flex" justify="center">
        <el-col class="myCreateOrdercol8" :span="1"></el-col>
        <el-col class="myCreateOrdercol8" :span="6">
            <div class="myCreateOrdercol8Spandiv">
                运费： 免运费
            </div>
        </el-col>
        <el-col class="myCreateOrdercol8" :span="7">
            <div class="myCreateOrdercol8Spandiv">
                优惠： -¥{{CCDiscount.toFixed(1)}}
            </div>
        </el-col>
        <el-col class="myCreateOrdercol8" :span="10">
            <div class="myCreateOrdercol8Spandiv" style="margin-right: 15px;">
                商品金额： <span style="color:rgb(228, 67, 102);">¥{{CCTotalRealprice.toFixed(1)}}</span>
            </div>
        </el-col>
    </el-row>
</div>
</template>

<script>
import axios from 'axios'
export default {
    name:'PxCOShowCart',
    data(){
        return{
            axiosCIDdate:[],
            CCList:'',
            axiosCCSData:[], //CCS是CheckedCartShow
            SmallJPGinfo:[],  //赋值为''则报错Cannot create property '0' on string ''
            BigPNGinfo:[],
            CCTotalPrice:0,
            CCTotalRealprice:0,
            CCDiscount:0,
            AxiosCidLength:0,
        }
    },
    mounted(){
		if(sessionStorage.getItem('axiosCIDdate') !=null){  //如果sessionStorage里的数据存在时
			if(this.$route.params.data !=null){             //如果路由有传来数据(购物车到创建订单),此时是没有关闭之前已经存在的创建订单页面而进行的路由跳转
                for( let i =0 ; i<this.$route.params.data.length ; i++){
                    if(this.$route.params.data[i].judge == true){
                        this.axiosCIDdate[this.AxiosCidLength] = this.$route.params.data[i].cid
                        this.AxiosCidLength++
                    }
                }
				sessionStorage.setItem('axiosCIDdate',JSON.stringify(this.axiosCIDdate))
			}else{              //如果路由没有传数据(路由没有跳转)      此时解释为刷新页面
				this.axiosCIDdate=JSON.parse(sessionStorage.getItem('axiosCIDdate'))
			}
		}else{	    //如果sessionStorage里没有数据(即路由有跳转)    此时解释为之前没有进入创建订单界面
            for( let i =0 ; i<this.$route.params.data.length ; i++){
                if(this.$route.params.data[i].judge == true){
                    this.axiosCIDdate[this.AxiosCidLength] = this.$route.params.data[i].cid
                    this.AxiosCidLength++
                }
            }
			sessionStorage.setItem('axiosCIDdate',JSON.stringify(this.axiosCIDdate))
		}
        for( let i=0 ; i<this.axiosCIDdate.length ; i++){
            this.$addr.get(`carts/list?cids=${this.axiosCIDdate[i]}`).then(
                response=>{
                    console.log('请求获取勾选的购物车信息成功了',response)
                    this.axiosCCSData[i]=response.data.data[0]
                    this.CCTotalPrice+=this.axiosCCSData[i].price*this.axiosCCSData[i].num
                    this.CCTotalRealprice+=this.axiosCCSData[i].realprice*this.axiosCCSData[i].num*0.6
                    this.SmallJPGinfo[i]=require(`../../../assets/${response.data.data[0].image.slice(13)}1.jpg`)
                    // this.BigPNGinfo[i]=require(`../../../assets/${response.data.data[0].image.slice(13)}1_big.png`)
                    this.CCDiscount=this.CCTotalPrice-this.CCTotalRealprice
                    this.$bus.$emit('TransferPrice',this.CCTotalPrice,this.CCDiscount,this.CCTotalRealprice)
                },
                error=>{
                    console.log('请求获取勾选的购物车信息失败了',error.message)
                }
            )
        }
        setTimeout(() => {
            // 增加定时器解决v-for无法快速遍历的bug
            this.CCList=this.axiosCCSData
            // this.CCList=[6,7,8],
            this.$bus.$emit('TransferCheckedCart',this.CCList)
        }, 400);
    },
}
</script>

<style scoped>
.myCreateOrderrow7{
    margin: 0 auto;
    max-width: 1000px;
    margin-top: 10px;
    height: 100%;
}
.myCreateOrdercol7{
    margin-left: 10px;
    margin-right: 10px;
    height: 50px;
}
.myCreateOrdercol7Leftdiv{
    margin-top: 0px;
    font-size: 12px;
}
.SmallJPG{
    width: 50px;
    height: 50px;
}
.ProductText{
    position: absolute;
    margin-left: 55px;
    margin-top: -46px;
    width: 100px;
    overflow: hidden;
    /* white-space: nowrap; 溢出不换行*/
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
}
.myCreateOrdercol7SpanRightdiv{
    margin-top: 10px;
}
.myCreateOrdercol7SpanRight{
    overflow: hidden;
    /* white-space: nowrap; 溢出不换行*/
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    font-size: 12px;
}
.myCreateOrderrow6{
    margin: 0 auto;
    max-width: 1000px;
    margin-top: 20px;
    height: 100%;
    border-bottom: 1px solid rgb(179, 179, 179 , 0.7);
}
.myCreateOrdercol6{
    margin-left: 10px;
    margin-right: 10px;
    height: 40px;
}
.myCreateOrdercol6SpanLeftdiv{
    margin-top: 10px;
}
.myCreateOrdercol6SpanLeft{
    font-weight: 550;
    width:135px;
}
.myCreateOrdercol6SpanRightdiv{
    text-align: center;
    margin-top: 10px;
}
.myCreateOrdercol6SpanRight{
    opacity: 0.7;
    font-size: 12px;
}
.myCreateOrderrow8{
    margin: 0 auto;
    max-width: 1000px;
    margin-top: 10px;
    height: 100%;
    border-top: 1px solid rgb(179, 179, 179 , 0.7);
}
.myCreateOrdercol8{
    margin-left: 6px;
    height: 40px;
}
.myCreateOrdercol8Spandiv{
    float: right;
    margin-top: 10px;
    font-weight: 550;
    font-size: 12px;
}
</style>